<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../jquery-1.8.2.min.js"></script>

<script src="../layui/layui.js" charset="utf-8"></script>
<link rel="stylesheet" href="../layui/css/layui.css"  media="all">

</head>
<body>
<form>
姓名:<input type="text" name="teaname" id="teaname3"/>
性别:<input type="radio" name="data1" value="女"/>女
  	<input type="radio" name="data1" value="男"/>男
  	<input type="radio" name="data1" value=""/>不明确<br/>
 
 部门：<select id="teadept" >
    <option value="">请选择</option>
  </select>
  <input type="button"  value="检索" onclick="search()"/>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>


<!-- 头部 -->
<script id="toolbarDemo" type="text/html">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" id="in" lay-event="getCheckData">导入</button>
 
    <button class="layui-btn layui-btn-sm" id="add" onclick="addtea()">添加</button>
  </div>
</script>

<!-- 添加表单 -->
<form class="layui-form" action="" lay-filter="savestu" onsubmit="return false" >
<div class="layui-form-item" style="display: none" id="save">

<div class="layui-form-item">
      <label class="layui-form-label">身份编号</label>
      <div class="layui-input-inline" >
        <input name="teaid" id="teaid2" class="layui-input" type="text" autocomplete="off" >
    </div>
    </div>
<div class="layui-form-item">
      <label class="layui-form-label">名字</label>
      <div class="layui-input-inline">
        <input name="teaname" id="teaname2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">密码</label>
      <div class="layui-input-inline">
        <input name="teapassword" id="teapassword2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">性别</label>
      <div class="layui-input-inline">
        <input name="data1" id="data12" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <input name="status" id="status2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
   
    
    <div class="layui-form-item">
      <label class="layui-form-label">部门</label>
      <div class="layui-input-inline">
        <input name=teadept id="teadept2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">已借书量（本）</label>
      <div class="layui-input-inline">
        <input name="teaborrowmaxnum" id="teaborrowmaxnum2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">最大借书数量（本）</label>
      <div class="layui-input-inline">
        <input name="teaborrowbooknum" id="teaborrowbooknum2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">已还书（本）</label>
      <div class="layui-input-inline">
        <input name="teagivebooknum" id="teagivebooknum2" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">借书时间</label>
      <div class="layui-input-inline">
        <input name="data2" id="data22" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">还书时间</label>
      <div class="layui-input-inline">
        <input name="data3" id="data32" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-input-block">
       <a class="layui-btn layui-btn-xs layui-btn-xs"  onclick="saveTeacher()">确定添加</a>
    </div>
  </div>
  </div>
</form>

<!-- 修改表单 -->
<form class="layui-form" action="" lay-filter="updatestu" onsubmit="return false" >
<div class="layui-form-item" style="display: none" id="up">

<div class="layui-form-item" style="display: none">
      <label class="layui-form-label">身份编号</label>
      <div class="layui-input-inline" >
        <input name="teaid" id="teaid1" class="layui-input" type="text" autocomplete="off" >
    </div>
    </div>
<div class="layui-form-item">
      <label class="layui-form-label">名字</label>
      <div class="layui-input-inline">
        <input name="teaname" id="teaname1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">密码</label>
      <div class="layui-input-inline">
        <input name="teapassword" id="teapassword1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">性别</label>
      <div class="layui-input-inline">
        <input name="data1" id="data11" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <input name="status" id="status1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
   
    
    <div class="layui-form-item">
      <label class="layui-form-label">部门</label>
      <div class="layui-input-inline">
        <input name=teadept id="teadept1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">已借书量（本）</label>
      <div class="layui-input-inline">
        <input name="teaborrowmaxnum" id="teaborrowmaxnum1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">最大借书数量（本）</label>
      <div class="layui-input-inline">
        <input name="teaborrowbooknum" id="teaborrowbooknum1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">已还书（本）</label>
      <div class="layui-input-inline">
        <input name="teagivebooknum" id="teagivebooknum1" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">借书时间</label>
      <div class="layui-input-inline">
        <input name="data2" id="data21" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">还书时间</label>
      <div class="layui-input-inline">
        <input name="data3" id="data31" class="layui-input" type="text" autocomplete="off" >
      </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-input-block">
       <a class="layui-btn layui-btn-xs layui-btn-xs"  onclick="updateTeacher()">修改</a>
    </div>
  </div>
  </div>
</form>
<!-- 修改按钮 -->
<script id="barDemo" type="text/html">
  <a class="layui-btn layui-btn-xs"   lay-event="edit">修改</a>
</script>


<!--数据表格  -->
 
<script>
$(function(){
	search();
	//下拉框
	$.ajax({
		url:"/querydept",
		data:{},
		dataType:"json",
		type:"post",
		success:function(res){
			if(res.length>0){
				for(var i =0;i<res.length;i++){
					$("#teadept").append("<option value='"+res[i]+"'>"+res[i]+"</option>");
				}
			}
		}
	})
})
var uploadInst;
var indexsave;
var tableindex;
var indexupdate;

function search(){
var teaname=$("#teaname3").val();
var  data1=$("input[type='radio']:checked").val();
var teadept=$("#teadept option:selected").val();
	layui.use(['table','upload','form','jquery'], function(){
		 var table = layui.table;
		  var upload=layui.upload;
		  var $=layui.jquery;
		  var form=layui.form;
		  
		  tableindex= table.render({
		    elem: '#test'
		    ,url:'/Teaquery'
		    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
		    ,where:{
			    	teaname:teaname,
			    	data1:data1,
			    	teadept:teadept
			    }
		    ,cols: [[
		      {field:'teaid', width:80, title: '身份编号', sort: true}
		      ,{field:'teaname', width:80, title: '姓名'}
		      ,{field:'teapassword', width:80, title: '密码'}
		      ,{field:'status', width:80, title: '状态'}//0学生，1老师
		      ,{field:'teadept', width:80, title: '部门', sort: true}
		      ,{field:'teaborrowmaxnum', width:80, title: '已借书量（本）'}
		      ,{field:'teaborrowbooknum', width:135, title: '最大借书数量（本）', sort: true}
		      ,{field:'teagivebooknum', width:135, title: '已还书（本）', sort: true}
		      ,{field:'data1', width:135, title: '性别', sort: true}
		      ,{field:'data2', width:135, title: '借书时间', sort: true}
		      ,{field:'data3', width:135, title: '还书时间', sort: true}
		      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
		    ]]
		    ,page: true
		  });
		  //导入
		  uploadInst = upload.render({
			    elem: '#in'			    
			    ,url:'../TeainExcel' //改成您自己的上传接口
			    ,accept:'file'//普通文件
			    ,exts:'xls|xlsx'//只允许压缩文件
			   ,method:"post"
			    ,done: function(res){
			      if(res.success){
			    	  layer.msg(res.message);
			    	tableObj.reload();
			      }
			      
			    }
			
			  });
		   
		  //监听行工具，修改
		   table.on('tool(test)', function(obj){
		   	 
		   		    var data = obj.data;
		   		    //console.log(obj)
		   		    if(obj.event === 'edit'){
		   		    	form.val('updatestu',data);
		   		    	indexupdate = layer.open({
		   		    		type: 1,
		   		    		title:"修改学生信息",
		   		    		area: ['500px', '550px'],
		   		    		content:$("#up")
		   		    	})
		   		    }
		   		    
		   		  })
	});
}
	  //修改方法
	  function updateTeacher(){
		var teaid=$("#teaid1").val();
		var teaname=$("#teaname1").val();
		var teapassword=$("#teapassword1").val();
		var status=$("#status1").val();
		var teadept=$("#teadept1").val();
		var teaborrowmaxnum=$("#teaborrowmaxnum1").val();
		var teaborrowbooknum=$("#teaborrowbooknum1").val();
		var teagivebooknum=$("#teagivebooknum1").val();
		var data1=$("#data11").val();
		var data2=$("#data21").val();
		var data3=$("#data31").val();
		$.ajax({
			url:"/Teaupdate",
			data:{
				teaid:teaid,
				teaname:teaname,
				teapassword:teapassword,
				status:status,
				teadept:teadept,
				teaborrowmaxnum:teaborrowmaxnum,
				teaborrowbooknum:teaborrowbooknum,
				teagivebooknum:teagivebooknum,
				data1:data1,
				data2:data2,
				data3:data3
			},
			type:"post",
			dataType:"json",
			success:function(res){
				if(res){
					layer.close(indexupdate);
					tableindex.reload();
				}else{
					layer.msg("修改失败");
				}
					
			}
		})
		
	  }
	  //添加方法
	  function saveTeacher(){
			var teaid=$("#teaid2").val();
			var teaname=$("#teaname2").val();
			var teapassword=$("#teapassword2").val();
			var status=$("#status2").val();
			var teadept=$("#teadept2").val();
			var teaborrowmaxnum=$("#teaborrowmaxnum2").val();
			var teaborrowbooknum=$("#teaborrowbooknum2").val();
			var teagivebooknum=$("#teagivebooknum2").val();
			var data1=$("#data12").val();
			var data2=$("#data22").val();
			var data3=$("#data32").val();
			$.ajax({
				url:"/Teasave",
				data:{
					teaid:teaid,
					teaname:teaname,
					teapassword:teapassword,
					status:status,
					teadept:teadept,
					teaborrowmaxnum:teaborrowmaxnum,
					teaborrowbooknum:teaborrowbooknum,
					teagivebooknum:teagivebooknum,
					data1:data1,
					data2:data2,
					data3:data3
				},
				type:"post",
				dataType:"json",
				success:function(res){
					if(res){
						layer.close(indexsave);
						tableindex.reload();
					}else{
						layer.msg("添加失败");
					}
						
				}
			})
			
		  }
	function addtea(){
		layui.use('layer', function(){
			var layer =layui.layer;
			indexsave = layer.open({
		    		type: 1,
		    		title:"添加学生信息",
		    		area: ['500px', '550px'],
		    		content:$("#save")
		    	})
		})
	}

		
</script>

</body>
</html>